<?php
namespace Admin\Model;

use Think\Model;
use Think\Verify;

class AdminModel extends Model
{
    /**
     * 分页条件查询
     * @param $map 查询条件
     * @param $pagenumber 页号
     * @param $pagesize 页面大小
     * @return mixed
     */
    public function getByConditionPage($map, $pagenumber, $pagesize)
    {
        $startno = ($pagenumber - 1) * $pagesize;
        $limit = $startno . ',' . $pagesize;//每页的数据数和内容$limit
        $list = $this->where($map)->limit($limit)->select();
        return $list;
    }


    public function getByConditionPageSchoolAdmin($map, $pagenumber, $pagesize)
    {
        $startno = ($pagenumber - 1) * $pagesize;
        $limit = $startno . ',' . $pagesize;//每页的数据数和内容$limit
        $list = $this->join('LEFT JOIN t_user ON t_admin.user_id=t_user.id')
            ->join('LEFT JOIN t_school ON t_user.school_id = t_school.id')->where($map)->limit($limit)->field('t_admin.id as adminid, t_user.nickname, t_user.username, t_school.*')->select();
        return $list;
    }

    /**
     * 通过用户名和密码查找
     * @param $username 用户名
     * @param $password 密码
     * @return mixed 管理员对象
     */
    public function getUsernameAndPassword($username, $password)
    {
        $password = md5($password . C('MD5_KEY'));
        $where['username'] = ':username';
        $where['password'] = ':password';
        $bind[':password'] = array($password, \PDO::PARAM_STR);
        $bind[':username'] = array($username, \PDO::PARAM_STR);
        $user = $this->where($where)->bind($bind)->find();
        return $user;
    }
}